/*
 * GeoEquilibrator.h
 *
 *  Created on: 17 Oct 2011
 *      Author: allan
 */

#ifndef GEOEQUILIBRATOR_H_
#define GEOEQUILIBRATOR_H_

// C++ includes
#include <map>
#include <string>
#include <vector>
using namespace std;

// GeoReact includes
#include <Core/EquilibriumConditions.h>
#include <Core/EquilibriumSolver.h>
#include <Utils/ConvergenceDiagnostics.h>

// GeoReact forward declarations
class GeoSystem;

class GeoEquilibrator
{
public:
	GeoEquilibrator();
	
	GeoEquilibrator(
		const Multiphase& multiphase,
		const ReactionSystem& equilibrium_reactions);
	
	void
	ImposeSpeciesMoles(const string& species, double moles);
	
	void
	ImposeSpeciesActivity(const string& species, double activity);
	
	void
	ImposeElementMoles(const string& element, double moles);
	
	void
	ImposeAcidity(double pH);	
	
	void
	ImposePartialPressureGas(const string& gas, double partial_pressure);
	
	void
	ImposeChargeBalance();
	
	void
	ResetConditions();
	
	const ConvergenceDiagnostics
	Equilibrate(double T, double P, VectorXd& n);
	
	const ConvergenceDiagnostics
	Equilibrate(GeoSystem& geosystem);
	
private:
	/// The multiphase instance
	Multiphase multiphase;
	
	/// The system of equilibrium-controlled reactions
	ReactionSystem equilibrium_reactions;
	
	/// The equilibrium conditions of the equilibrium problem
	vector<EquilibriumCondition> conditions;
	
	/// The equilibrium solver to solve the equilibrium problem
	EquilibriumSolver equilibrium_solver;
	
	/// The composition guess (as a map) of some species in the system
	map<string,double> composition_guess;
};

#endif /* GEOEQUILIBRATOR_H_ */
